/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.tesoreria.beans;

import java.util.List;
import javax.faces.model.SelectItem;
import org.cip.esymons.eventos.be.Ambiente;

import org.cip.esymons.tesoreria.bc.AmbienteTesoreriaDelegate;

/**
 *
 * @author Ingrid Capuñay
 */
public class AmbienteTesoreriaController {
    private AmbienteTesoreriaDelegate delegado;
    public AmbienteTesoreriaController() {
        delegado= new AmbienteTesoreriaDelegate();
    }
    public Ambiente buscarPorCodigo(Integer id){
        try{
            return delegado.buscarUnAmbiente(id);
        }catch(Exception ex){
            return null;
        }
    }
    public SelectItem[] getAmbienteItem() {
        try {
            List<Ambiente> la = delegado.listarTodosAmbientes();
            SelectItem[] select = new SelectItem[la.size()];
            int i = 0;
            for (Ambiente ev : la) {
                SelectItem item = new SelectItem(ev, ev.getAmbNombre());
                select[i++] = item;
            }

            return select;

        } catch (Exception ex) {
            SelectItem[] select = new SelectItem[1];
            SelectItem item = new SelectItem(null,"No existen Ambientes");
            select[0] = item;
            return select;
        }
    }
}
